package com.pym.Contooller.Config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;
@PropertySource("classpath:jdbc.properties")
public class JDBCConfig {
    @Value("${jdbc.url}")
    private String URl;
    @Value("${jdbc.username}")
    private String username;
    @Value("${jdbc.password}")
    private String password;
    @Value("${jdbc.Driver}")
    private String driver;
//配置数据源
    @Bean
    public DataSource dataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        System.out.println(password);
        System.out.println(driver);
        System.out.println(username);
        System.out.println(URl);
        dataSource.setDriverClassName(driver);
        dataSource.setUrl(URl);
        dataSource.setPassword(password);
        dataSource.setUsername(username);
        return dataSource;
    }
    //相当与添加数据源
    @Bean
    public PlatformTransactionManager transactionManager(DataSource dataSource) {
        DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(dataSource);
        return transactionManager;
    }

}
